namespace TomatoBreak.Web
{
    using System;
    using System.Collections.Generic;
    using System.Web.Mvc;

    using Combres;

    public static class AssetsHelper
    {
        private static readonly IDictionary<string, string> cdnAssets = BuildCDNAssets();

        public static string Asset(this UrlHelper instance, string setName)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            if (!instance.RequestContext.HttpContext.IsDebuggingEnabled &&
                cdnAssets.ContainsKey(setName))
            {
                return cdnAssets[setName];
            }

            return WebExtensions.CombresUrl(setName);
        }

        public static string Image(this UrlHelper instance, string fileName)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            var path = instance.Content("~/assets/images/" + fileName);

            return path;
        }

        private static IDictionary<string, string> BuildCDNAssets()
        {
            return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "jquery-mobile-css", "http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.css" },
                { "jquery-js", "http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" },
                { "jquery-mobile-js", "http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js" }
            };
        }
    }
}